package com.example.tse.rbyair.downloadresponsibility;

import android.support.v4.app.FragmentActivity;

import com.example.tse.rbyair.dialog.CheckUpdateDialog;
import com.example.tse.rbyair.util.AppInforUtil;

/**
 * Created by tse on 16/1/13.
 */
public class CheckUpdateHandler extends DownLoadHandler {


    private final static int Type_NO_Need_Update = 0;
    private final static int Type_Chioce_Update = 1;
    private final static int Type_Force_Update = 2;


    private static int Type_Update = -1;

    @Override
    public void handlerRequest(final FragmentActivity activity) {


//        AppInforUtil.MinAndroidVersion

        if (AppInforUtil.AppVersionCode >= AppInforUtil.LastestVersion) {
            Type_Update = Type_NO_Need_Update;
        } else if (AppInforUtil.AppVersionCode < AppInforUtil.MinAndroidVersion) {
            Type_Update = Type_Force_Update;
        } else {
            Type_Update = Type_Chioce_Update;
        }

        switch (Type_Update) {
            case Type_NO_Need_Update:

//                L.d("CheckUpdateHandler Type_Chioce_Update:" + Type_NO_Need_Update);
                return;

            case Type_Chioce_Update:


//                L.d("CheckUpdateHandler Type_Chioce_Update:" + Type_Chioce_Update);
                final CheckUpdateDialog checkUpdateDialog = new CheckUpdateDialog();


                checkUpdateDialog.setOnOkClickLitener(new CheckUpdateDialog.OnOkClickLitener() {
                    @Override
                    public void OK() {
                        getSuccessor().handlerRequest(activity);

                    }

                    @Override
                    public void Cancel() {

                        return;

                    }
                });

                    checkUpdateDialog.show(activity.getSupportFragmentManager(), "ss");
                break;

            case Type_Force_Update:
//                L.d("CheckUpdateHandler Type_Force_Update:" + Type_Force_Update);

                getSuccessor().handlerRequest(activity);

                break;

            default:
                return;


        }


    }


}
